<template>
  <div class="main-bg">
    <!-- 左侧固定目录 -->
    <div class="toc-sidebar" v-if="headings.length > 0 && !tocCollapsed">
      <div class="toc-header">
        <h3>目录</h3>
        <button class="toc-toggle" @click="toggleToc" title="收起目录">
          <i class="fas fa-chevron-left"></i>
        </button>
      </div>
      <div class="toc-content">
        <ul class="toc-menu">
          <li v-for="item in headings" :key="item.id" :class="`level-${item.level}`">
            <a :href="'#' + item.id"
               :class="{ active: activeHeading === item.id }"
               @click.prevent="scrollToHeading(item.id)"
               :title="item.text">
              {{ item.text }}
            </a>
          </li>
        </ul>
      </div>
    </div>

    <!-- 统一的内容容器 -->
    <div class="page-container" :class="{ 'has-toc': headings.length > 0 }">
      <!-- 标题区域 -->
      <div class="header">
        <h1>Java语法基础</h1>
        <p>全面掌握Java编程语言的核心语法与最佳实践</p>
      </div>

      <!-- 主内容区域 -->
      <div class="main-content">
        <div class="markdown-container">
          <div class="content-wrapper" v-html="compiledMarkdown"></div>
        </div>
      </div>
    </div>

    <!-- 功能按钮区域 -->
    <div class="action-buttons" v-if="headings.length > 0">
      <button class="action-btn" @click="goHome" title="返回首页">
        <i class="fas fa-home"></i>
      </button>
      <button class="action-btn" @click="toggleTheme" title="切换主题">
        <i class="fas fa-palette"></i>
      </button>
      <button class="action-btn" @click="toggleFullscreen" title="全屏阅读">
        <i class="fas fa-expand"></i>
      </button>
      <button class="action-btn" @click="shareContent" title="分享内容">
        <i class="fas fa-share-alt"></i>
      </button>
      <button class="action-btn" @click="bookmarkContent" title="收藏页面">
        <i class="fas fa-bookmark"></i>
      </button>
    </div>

    <!-- 目录收起状态的悬浮按钮 -->
    <div class="toc-float-button" v-if="headings.length > 0 && tocCollapsed" @click="toggleToc">
      <i class="fas fa-list"></i>
      <span class="float-btn-text">目录</span>
    </div>

    <!-- 回到顶部 -->
    <el-backtop :right="80" :bottom="40" :visibility-height="200">
      <div class="back-top-button">
        <i class="fas fa-arrow-up"></i>
      </div>
    </el-backtop>
  </div>
</template>

<script setup>
import { ref, computed, onMounted, nextTick } from 'vue'
import { useRoute } from 'vue-router'
import { marked } from 'marked'
import Prism from 'prismjs'
import 'prismjs/themes/prism-tomorrow.min.css'
import 'prismjs/plugins/line-numbers/prism-line-numbers.min.css'
import 'prismjs/plugins/line-numbers/prism-line-numbers.min.js'
// import 'prismjs/plugins/toolbar/prism-toolbar.css'
// import 'prismjs/plugins/toolbar/prism-toolbar.js'
// import 'prismjs/plugins/previewers/prism-previewers.min.css'
// import 'prismjs/plugins/previewers/prism-previewers.min.js'
// import 'prismjs/plugins/show-language/prism-show-language.js'
import 'prismjs/plugins/autoloader/prism-autoloader.min.js'
import 'prismjs/plugins/normalize-whitespace/prism-normalize-whitespace.min.js'
// import 'prismjs/plugins/copy-to-clipboard/prism-copy-to-clipboard.js'
import 'prismjs/plugins/autolinker/prism-autolinker.min.css'
import 'prismjs/plugins/autolinker/prism-autolinker.min.js'
import 'prismjs/components/prism-java'
import 'prismjs/components/prism-css'
import 'prismjs/components/prism-javascript'
import 'prismjs/components/prism-python'
// 可按需引入其它语言

const route = useRoute()
console.log(route)
const markdownContent = ref('')
const pageTitle = ref('')
const headings = ref([])
const activeHeading = ref('')
const tocCollapsed = ref(false)

function extractHeadings(md) {
  const lines = md.split('\n');
  const result = [];
  lines.forEach((line, idx) => {
    const match = /^(#{2,3})\s+(.+)/.exec(line);
    if (match) {
      const level = match[1].length;
      const text = match[2].trim();
      const id = 'heading-' + idx + '-' + text.replace(/\s+/g, '-').replace(/[^\w-]/g, '');
      result.push({ text, level, id });
    }
  });
  return result;
}

const renderer = new marked.Renderer();

// 自定义按钮配置 - 根据语言类型动态生成
function getCustomButtons(language) {
  const buttons = [];

  // 只有HTML代码块才显示运行按钮
  if (language === 'html') {
    buttons.push({
      id: 'run',
      text: '运行',
      icon: '▶️',
      onClick: (code, lang) => {
        runHtmlCode(code);
      }
    });
  }

  return buttons;
}

// 运行HTML代码的函数 - 在新标签页中打开
function runHtmlCode(htmlCode) {
  try {
    // 将HTML内容存储到sessionStorage
    sessionStorage.setItem('htmlPreviewContent', htmlCode);

    // 构建预览页面的URL（不带参数）
    const baseUrl = window.location.origin;
    const previewUrl = `${baseUrl}/html-preview`;

    // 在新标签页中打开预览页面
    const previewWindow = window.open(previewUrl, '_blank');

    if (previewWindow) {
      previewWindow.focus();
    } else {
      // 如果弹窗被阻止，提示用户
      alert('请允许弹窗以查看HTML预览页面，或检查浏览器的弹窗拦截设置');
    }
  } catch (error) {
    console.error('打开预览页面失败:', error);
    alert('预览功能暂时不可用，请稍后重试');
  }
}

renderer.code = (code, language) => {
  const lang = language && Prism.languages[language] ? language : 'clike';
  const highlighted = Prism.highlight(code, Prism.languages[lang], lang);

  // 根据语言类型获取自定义按钮
  const customButtons = getCustomButtons(lang);

  // 生成自定义按钮HTML
  const customButtonsHtml = customButtons.map(btn => `
    <button class="custom-btn" data-btn-id="${btn.id}" title="${btn.text}">
      ${btn.icon} ${btn.text}
    </button>
  `).join('');

  return `
    <div class="code-block-wrapper" data-language="${lang}">
      <div class="code-toolbar">
        <span class="language-label">${lang}</span>
        <div class="toolbar-buttons">
          ${customButtonsHtml}
          <button class="copy-btn" data-copy-btn>📋 复制</button>
        </div>
      </div>
      <pre class="line-numbers"><code class="language-${lang}" data-code>${highlighted}</code></pre>
    </div>
  `;
};

renderer.heading = function (text, level, raw, slugger) {
  if (level === 2 || level === 3) {
    const heading = headings.value.find(h => h.text === text && h.level === level);
    const id = heading ? heading.id : slugger.slug(text);
    return `<h${level} id="${id}" class="md-heading">${text}</h${level}>`;
  }
  return `<h${level}>${text}</h${level}>`;
};

marked.use({ renderer });

const compiledMarkdown = computed(() => marked(markdownContent.value))

function scrollToHeading(id) {
  const el = document.getElementById(id);
  if (el) {
    el.scrollIntoView({ behavior: 'smooth', block: 'start' });
    activeHeading.value = id;
  }
}

function toggleToc() {
  tocCollapsed.value = !tocCollapsed.value;
}

// 功能按钮的方法
function goHome() {
  // 返回首页功能
  window.location.href = '/';
}

function toggleTheme() {
  // 主题切换功能
  const body = document.body;
  const isDark = body.classList.contains('dark-theme');

  if (isDark) {
    body.classList.remove('dark-theme');
    body.classList.add('light-theme');
    localStorage.setItem('theme', 'light');
  } else {
    body.classList.remove('light-theme');
    body.classList.add('dark-theme');
    localStorage.setItem('theme', 'dark');
  }
}

function toggleFullscreen() {
  // 后续实现全屏功能
  if (!document.fullscreenElement) {
    document.documentElement.requestFullscreen();
  } else {
    document.exitFullscreen();
  }
}

function shareContent() {
  // 后续实现分享功能
  if (navigator.share) {
    navigator.share({
      title: pageTitle.value,
      url: window.location.href
    });
  } else {
    // 复制链接到剪贴板
    navigator.clipboard.writeText(window.location.href);
    alert('链接已复制到剪贴板');
  }
}

function bookmarkContent() {
  // 后续实现收藏功能
  console.log('收藏页面');
}

function onScroll() {
  const headingEls = headings.value.map(h => document.getElementById(h.id)).filter(Boolean);
  const scrollTop = window.scrollY || document.documentElement.scrollTop;
  let current = '';
  for (let i = 0; i < headingEls.length; i++) {
    if (headingEls[i].getBoundingClientRect().top + window.scrollY - 120 <= scrollTop) {
      current = headings.value[i].id;
    }
  }
  activeHeading.value = current;
}

const loadMarkdownContent = async () => {
  try {
    const response = await fetch(`/markdown/java-basic/${route.params.topic}.md`)
    if (!response.ok) throw new Error('Failed to load content')
    markdownContent.value = await response.text()
    const firstLine = markdownContent.value.split('\n')[0]
    pageTitle.value = firstLine.replace(/^#\s*/, '')
    headings.value = extractHeadings(markdownContent.value)

    // 使用nextTick确保DOM已更新
    await nextTick(() => {
      // 初始化Prism高亮
      Prism.highlightAll();

      // 设置代码块事件监听
      setupCodeBlockEvents();
    });

    window.addEventListener('scroll', onScroll)
  } catch (error) {
    console.error('Error loading markdown:', error)
    markdownContent.value = '# Error\nFailed to load content.'
    pageTitle.value = '加载失败'
    headings.value = []
  }
}

// 处理自定义按钮点击事件
function setupCodeBlockEvents() {
  document.querySelectorAll('.code-block-wrapper').forEach(wrapper => {
    const codeElement = wrapper.querySelector('[data-code]');
    const code = codeElement.textContent;
    const language = wrapper.dataset.language || 'text';

    // 设置复制按钮
    const copyBtn = wrapper.querySelector('[data-copy-btn]');
    copyBtn.addEventListener('click', async () => {
      try {
        await navigator.clipboard.writeText(code);
        copyBtn.textContent = '✅ 已复制';
        setTimeout(() => {
          copyBtn.textContent = '📋 复制';
        }, 2000);
      } catch (err) {
        console.error('复制失败:', err);
        copyBtn.textContent = '❌ 复制失败';
      }
    });

    // 设置自定义按钮（根据语言类型）
    const customButtons = getCustomButtons(language);
    customButtons.forEach(btn => {
      const btnElement = wrapper.querySelector(`[data-btn-id="${btn.id}"]`);
      if (btnElement) {
        btnElement.addEventListener('click', () => btn.onClick(code, language));
      }
    });
  });
}

onMounted(() => {
  loadMarkdownContent();
  // 在内容加载完成后设置事件监听
  nextTick(() => {
    setupCodeBlockEvents();
  });

  // 初始化主题
  initTheme();
});

// 初始化主题
function initTheme() {
  const savedTheme = localStorage.getItem('theme') || 'light';
  const body = document.body;

  if (savedTheme === 'dark') {
    body.classList.remove('light-theme');
    body.classList.add('dark-theme');
  } else {
    body.classList.remove('dark-theme');
    body.classList.add('light-theme');
  }
}
</script>

<style>
:root {
  --primary: #42b983;
  --primary-dark: #359e70;
  --secondary: #2c3e50;
  --text-primary: #333;
  --text-secondary: #666;
  --text-light: #888;
  --bg-light: #f8fafc;
  --border-light: #eaeef2;
  --accent-purple: #c678dd;
  --accent-blue: #61afef;
  --accent-green: #98c379;
}

.main-bg {
  min-height: 100vh;
  padding: 20px 0 20px 0; /* 减少上方空间 */
  background: linear-gradient(135deg, #f5f7fa 0%, #e4edf5 100%);
}

.header {
  text-align: center;
  padding: 30px 0;
  margin-bottom: 20px;
  background: linear-gradient(120deg, var(--primary), #2c3e50);
  color: white;
  border-radius: 12px;
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}
.header h1 {
  font-size: 2.8rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 10px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.header p {
  font-size: 1.2rem;
  font-weight: 300;
  max-width: 600px;
  margin: 0 auto;
  opacity: 0.9;
}

.page-container {
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
  padding: 0 20px;
}

.page-container.has-toc {
  margin-left: 320px; /* 为左侧目录留出空间 */
}

/* 功能按钮区域 */
.action-buttons {
  position: fixed;
  top: 120px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 102;
}

.action-btn {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--primary), #2c3e50);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(66, 185, 131, 0.3);
  position: relative;
  overflow: hidden;
}

.action-btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  transition: all 0.3s ease;
  transform: translate(-50%, -50%);
}

.action-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(66, 185, 131, 0.4);
}

.action-btn:hover::before {
  width: 100%;
  height: 100%;
}

.action-btn:active {
  transform: scale(0.95);
}

/* 左侧目录样式 */
.toc-sidebar {
  position: fixed;
  top: 90px; /* 调整位置 */
  left: 20px;
  width: 280px;
  max-height: calc(100vh - 140px); /* 确保不溢出底部 */
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
  z-index: 100;
  transition: all 0.3s ease;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.toc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid var(--border-light);
  background: linear-gradient(135deg, var(--primary), #2c3e50);
  color: white;
  border-radius: 12px 12px 0 0;
}

.toc-header h3 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  white-space: nowrap;
}

.toc-toggle {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.toc-toggle:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.toc-content {
  padding: 15px 0;
  max-height: calc(100vh - 220px); /* 修复溢出问题 */
  overflow-y: auto;
}

.toc-content::-webkit-scrollbar {
  width: 4px;
}

.toc-content::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.toc-content::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 2px;
}

.toc-menu {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-menu li {
  margin: 0;
}

.toc-menu li.level-2 {
  padding-left: 0;
}

.toc-menu li.level-3 {
  padding-left: 20px;
}

.toc-menu li.level-4 {
  padding-left: 40px;
}

.toc-menu a {
  display: block;
  text-decoration: none;
  color: var(--text-primary);
  padding: 8px 20px;
  font-size: 0.9rem;
  line-height: 1.4;
  transition: all 0.3s ease;
  border-left: 3px solid transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-menu a:hover {
  background: rgba(66, 185, 131, 0.1);
  color: var(--primary);
  border-left-color: var(--primary);
}

.toc-menu a.active {
  background: rgba(66, 185, 131, 0.15);
  color: var(--primary);
  font-weight: 600;
  border-left-color: var(--primary);
}

/* 悬浮按钮 */
.toc-float-button {
  position: fixed;
  top: 120px;
  left: 20px;
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, #ff6b6b, #ee5a24);
  color: white;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
  transition: all 0.3s ease;
  z-index: 101;
  border: 3px solid rgba(255, 255, 255, 0.9);
}

.toc-float-button:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 25px rgba(255, 107, 107, 0.5);
}

.toc-float-button i {
  font-size: 1.2rem;
  margin-bottom: 2px;
}

.float-btn-text {
  font-size: 0.7rem;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.main-content {
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.05);
  overflow: hidden;
  width: 100%;
}

.markdown-container {
  padding: 40px;
}

.custom-title {
  color: var(--secondary);
  font-size: 2.4rem;
  margin-bottom: 30px;
  padding-bottom: 20px;
  position: relative;
  font-weight: 700;
}
.custom-title::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100px;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), var(--accent-blue));
  border-radius: 2px;
}

.content-wrapper {
  font-size: 1.1rem;
  line-height: 1.8;
  color: var(--text-secondary);
}
.content-wrapper h2 {
  color: var(--secondary);
  margin: 35px 0 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-light);
  font-weight: 600;
}
.content-wrapper h3 {
  color: var(--secondary);
  margin: 30px 0 15px;
  font-weight: 600;
}
.content-wrapper p {
  margin-bottom: 20px;
}
.content-wrapper blockquote {
  background: rgba(66, 185, 131, 0.06);
  border-left: 4px solid var(--primary);
  padding: 20px;
  margin: 25px 0;
  border-radius: 0 8px 8px 0;
}
.content-wrapper blockquote p {
  color: var(--text-primary);
  margin: 0;
}
.content-wrapper ul, .content-wrapper ol {
  margin: 20px 0 20px 30px;
  padding: 0;
}
.content-wrapper li {
  margin-bottom: 10px;
}

.md-heading {
  scroll-margin-top: 120px;
}

@media (max-width: 1024px) {
  .page-container {
    padding: 0 15px;
  }

  .page-container.has-toc {
    margin-left: 0;
  }

  .toc-sidebar {
    left: 15px;
    width: 260px;
  }

  .action-buttons {
    right: 15px;
  }

  .toc-float-button {
    left: 15px;
  }
}

@media (max-width: 768px) {
  .page-container {
    padding: 0 10px;
  }

  .page-container.has-toc {
    margin-left: 0;
  }

  .markdown-container {
    padding: 25px;
  }

  .action-buttons {
    top: 100px;
    right: 10px;
    flex-direction: row;
    gap: 8px;
  }

  .action-btn {
    width: 40px;
    height: 40px;
    font-size: 0.9rem;
  }

  .toc-sidebar {
    position: fixed;
    top: auto;
    bottom: 20px;
    left: 10px;
    right: 10px;
    width: auto;
    max-height: 50vh;
  }

  .toc-float-button {
    bottom: 80px;
    top: auto;
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 50px;
  }

  .float-btn-text {
    font-size: 0.6rem;
  }

  .header h1 {
    font-size: 2.2rem;
  }

  .custom-title {
    font-size: 2rem;
  }

  .markdown-container {
    padding: 25px;
  }

  .header h1 {
    font-size: 2.2rem;
  }

  .custom-title {
    font-size: 2rem;
  }

  .toc-menu a {
    font-size: 0.85rem;
    padding: 6px 15px;
  }

  .toc-header {
    padding: 15px;
  }

  .toc-header h3 {
    font-size: 1rem;
  }
}

/* 代码块容器样式 */
.code-block-wrapper {
  margin: 20px 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #2d2d2d;
  background-color: #2d2d2d;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* 工具栏样式 */
.code-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background-color: #363636;
  border-bottom: 1px solid #444;
}

.language-label {
  font-size: 0.85rem;
  color: #e6e6e6;
  font-weight: 500;
  text-transform: uppercase;
  background-color: #4a4a4a;
  padding: 3px 8px;
  border-radius: 3px;
}

.toolbar-buttons {
  display: flex;
  gap: 8px;
}

/* 按钮样式 */
.toolbar-buttons button {
  background-color: #4a4a4a;
  color: #e6e6e6;
  border: none;
  border-radius: 3px;
  padding: 4px 10px;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background-color 0.2s;
}

.toolbar-buttons button:hover {
  background-color: #5a5a5a;
}

.copy-btn {
  background-color: #2c5282 !important;
}

.copy-btn:hover {
  background-color: #3182ce !important;
}

.custom-btn {
  background-color: #553c9a !important;
}

.custom-btn:hover {
  background-color: #6b46c1 !important;
}

/* 确保行号样式正确 */
.line-numbers .line-numbers-rows {
  border-right: 1px solid #444;
}

.line-numbers-rows > span:before {
  color: #888;
}

/* 确保代码块内容正确显示 */
.code-block-wrapper pre {
  margin: 0;
  border-radius: 0 0 8px 8px;
  max-height: 500px;
  overflow: auto;
  /* 自定义滚动条样式 */
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
  transition: scrollbar-color 0.3s ease;
}

/* 默认状态：滚动条几乎透明 */
.code-block-wrapper pre::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.code-block-wrapper pre::-webkit-scrollbar-track {
  background: transparent;
}

.code-block-wrapper pre::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  transition: background 0.3s ease;
}

.code-block-wrapper pre::-webkit-scrollbar-corner {
  background: transparent;
}

/* 悬停状态：显示更明显的滚动条 */
.code-block-wrapper:hover pre {
  scrollbar-color: rgba(255, 255, 255, 0.3) rgba(255, 255, 255, 0.1);
}

.code-block-wrapper:hover pre::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.4);
}

.code-block-wrapper:hover pre::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.6);
}

.code-block-wrapper code {
  font-family: 'Fira Code', monospace;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* 回到顶部按钮样式 */
.back-top-button {
  width: 50px;
  height: 50px;
  background: linear-gradient(135deg, var(--primary), #2c3e50);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 4px 15px rgba(66, 185, 131, 0.3);
  transition: all 0.3s ease;
}

.back-top-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(66, 185, 131, 0.4);
}

/* 暗色主题样式 */
body.dark-theme {
  background-color: #1a1a1a;
  color: #e0e0e0;
}

body.dark-theme .main-bg {
  background: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
}

body.dark-theme .header {
  background: linear-gradient(120deg, #4a5568, #2d3748);
}

body.dark-theme .main-content,
body.dark-theme .toc-sidebar {
  background: #2d3748;
  border: 1px solid #4a5568;
}

body.dark-theme .content-wrapper {
  color: #e0e0e0;
}

body.dark-theme .content-wrapper h2,
body.dark-theme .content-wrapper h3 {
  color: #f7fafc;
}

body.dark-theme .toc-menu a {
  color: #e0e0e0;
}

body.dark-theme .toc-menu a:hover,
body.dark-theme .toc-menu a.active {
  background: rgba(66, 185, 131, 0.2);
  color: var(--primary);
}

/* 浅色主题样式（默认） */
body.light-theme {
  background-color: #ffffff;
  color: #333333;
}
</style>

